﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TianShu.Service.Contracts.Service.Crud;
using TianShu.Service.Dtos;

namespace TianShu.WebApi.ControllerBases
{
    [Route("api/[controller]")]
    [ApiController]
    public class TianShuUpdateController<TKey, TUpdateDto, TDetailDto> : TianShuController
    {
        IUpdateService<TKey, TUpdateDto, TDetailDto> UpdateService;
        public TianShuUpdateController(IUpdateService<TKey, TUpdateDto, TDetailDto> updateService)
        {
            this.UpdateService = updateService;
        }

        [HttpPost("update")]
        public virtual async Task<IActionResult> Update([FromQuery] TKey id, [FromBody] TUpdateDto input)
        {
            var result = await UpdateService.UpdateAsync(id, input);
            return Json(result);
        }
    }

    public class TianShuUpdateController<TKey, TUpdateDto> : TianShuUpdateController<TKey, TUpdateDto, TUpdateDto>
    {
        public TianShuUpdateController(IUpdateService<TKey, TUpdateDto, TUpdateDto> updateService):base(updateService)
        {
        }

    }
}
